
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/1/8
 * Time: 16:01
 */
Class LoginAction extends Action{

    /**
     * 显示登录模板
     */
     public function index(){
           $this->display();
     }

     // 登录处理
     Public function login(){
           $username = $this->_post('login_name');
           $pwd = Md5($this->_post('login_pwd'));
           if(empty($username)||empty($pwd)){
                 $this->redirect("Login/Index",array("code"=>401,'msg'=>"fail"));
                 exit();
           }
           $data['username'] = $username;
           $data['pwd'] = $pwd;
           $loginRes = D('Login')->checkLogin($data);

           if(!$loginRes){
               $this->redirect("Login/Index",array("code"=>401,'msg'=>"fail"));
               exit();
           }

           D("Login")->security_check($loginRes); // 安全检测

           if($loginRes){
                 // uid username 加密 加密用户id
                 cookie("loginId",$loginRes['id']);
                 $this->redirect("Index/Index");
           }
     }
     // 登出处理
     Public function loginOut(){
          // 销毁cookie
          cookie('loginId',null);
          $this->redirect('Login/Index');
     }
}